﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;


namespace GraphGeneration
{
   public class Graph : IGraph, IEnumerable
    {

        public List<Edge> EdgeList { get; private set; }
        public List<Vertex> VertexList { get; private set; }
        public int VertexCount { get { return VertexList.Count; } }

        public int getVertexID()
        {
            return VertexCount;
        }

        public Graph()
        {
            EdgeList = new List<Edge>();
            VertexList = new List<Vertex>();
        }

        public Vertex addVertex()
        {
            Vertex V = new Vertex(this);
            VertexList.Add(V);
            return V;
        }

        public IEnumerator GetEnumerator()
        {
            return EdgeList.GetEnumerator();
        }

        public Vertex addVertex(Vertex V)
        {
            VertexList.Add(V);
            return V;
        }

        public Edge addEdge(Vertex from, Vertex to, double weight)
        {
            Edge E = new Edge(from, to, weight);
            EdgeList.Add(E);
            return E;
        }

        public Edge addEdge(Vertex from, Vertex to)
        {
            Edge E = new Edge(from, to);
            EdgeList.Add(E);
            return E;
        }

        public void addEdge(Edge e)
        {
            EdgeList.Add(e);
        }


        public ArrayList PrintGraph()
        {
            ArrayList s = new ArrayList();

            s.Add(VertexCount.ToString());
            s.Add(EdgeList.Count.ToString());

            foreach (var E in EdgeList)
            {
                s.Add((E.getVertex()[0]).ToString() + " " + (E.getVertex()[1]).ToString() + " " + E.Weight.ToString());
            }
            return s;
        }

    }
}
